package cn.gengms.chat;


import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
//import javax.validation.ConstraintViolationException;

/**
 * 统一异常处理类
 */

@ControllerAdvice //声明该类是一个增强类
public class BaseException {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e, HttpServletRequest request){
        System.out.println("----error----");
        //log.error(" 错误信息： " + e.toString()+ " ,接口URL: " + request.getRequestURL().toString().substring(22));

        ChatApplication.errorLogger.error("错误信息:{},接口URL:{}",e.toString(),request.getRequestURI());
        e.printStackTrace();
        /*if(e.getMessage().equals("无token，请登录")|| e.getMessage().equals("token 无效，请重新获取")){
            return new Result(403,"token失效");
        }*/
      /*  if(e instanceof ConstraintViolationException){
            return new Result(404,"参数错误");
        }*/
        return new Result(500,"服务器错误",e.getCause());
    }



}
